package com.xinya.wanandroidclient.adapter

import android.text.Html
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xinya.wanandroidclient.R
import com.xinya.wanandroidclient.bean.HomeArticleBean
import com.xinya.wanandroidclient.utils.ColorUtils

/**
 *
 * @ClassName:      HomeArticleAdapter$
 * @Description:    java类作用描述
 * @Author:         xinya
 * @CreateDate:     2021/2/25$ 11:07$
 * @UpdateRemark:   更新内容
 * @Version:        1.0
 */
class HomeArticleAdapter : BaseQuickAdapter<HomeArticleBean.Data, BaseViewHolder> {
    companion object {
        private const val TAG = "HomeArticleAdapter"
    }

    constructor(dataList: MutableList<HomeArticleBean.Data>?) : super(
        R.layout.item_article,
        dataList
    )


    override fun convert(holder: BaseViewHolder, item: HomeArticleBean.Data) {
        // 是否为热门文章
        holder.getView<TextView>(R.id.tv_isTop).visibility =
            if (item.type == 1) View.VISIBLE else View.GONE
        // 是否为新文章
        holder.getView<TextView>(R.id.tv_isNew).visibility =
            if (item.fresh) View.VISIBLE else View.GONE
        // tab标签
        holder.setText(R.id.tv_article_tag, item.superChapterName)
        // 文章时间
        holder.setText(R.id.tv_article_data, item.niceDate)
        // 文章标题
        holder.setText(R.id.tv_article_title, Html.fromHtml(item.title))
        holder.getView<TextView>(R.id.tv_article_title).setTextColor(
            if (item.isRead) ColorUtils.parseColor(R.color.black_primary)
            else ColorUtils.parseColor(R.color.black)
        )
        // 文章作者或ahapter
        if (TextUtils.isEmpty(item.author)) {
            holder.setText(R.id.tv_article_author, item.chapterName)
        } else {
            holder.setText(R.id.tv_article_author, item.author)
        }
        // 是否已经收藏
        holder.getView<ImageView>(R.id.iv_article_like).setImageResource(
            if (item.collect) R.mipmap.favorites_red else R.mipmap.favorites
        )


    }
}